package com.financing.wap.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.financing.wap.common.Pager;
import com.financing.wap.dao.IScheduleDao;
import com.financing.wap.dto.ScheduleDTO;
import com.financing.wap.dto.TaskDTO;
import com.financing.wap.service.IScheduleService;
import com.financing.wap.util.Constants;

@Service("scheduleService")
public class ScheduleServiceImpl implements IScheduleService {

	@Autowired
	public IScheduleDao scheduleDao;
	
	@Override
	public boolean add(TaskDTO task) {
		task.setStatus(Constants.SCHEDULE_STATUS_UNSUCCESS);
		return scheduleDao.add(task);
	}

	@Override
	public List<ScheduleDTO> list(Pager pager, ScheduleDTO schedule) {
		List<ScheduleDTO> list = scheduleDao.list(pager, schedule);
		if(list!=null && !list.isEmpty()){
			for(int i=0; i<list.size(); i++){
				ScheduleDTO scheduleDto = list.get(i);
				List<TaskDTO> taskList = scheduleDao.dayTaskList(scheduleDto);
				scheduleDto.setTaskList(taskList);
			}
		}
		return list;
	}

	@Override
	public boolean updateTaskStatus(TaskDTO task) {
		return  scheduleDao.updateTaskStatus(task);
	}

	@Override
	public TaskDTO queryTaskById(TaskDTO task) {
		return scheduleDao.queryTaskById(task);
	}

}
